#include <cstdio>
#pragma GCC optimize(2,3,"Ofast")
#include <algorithm>
#include <vector>
using namespace std;
char buf[1<<25],*pbuf=buf;
template<typename T>
T read(){
	char c=*pbuf++;T x=0;
	while(c<48||c>57) c=*pbuf++;
	do x=(x<<1)+(x<<3)+(c^48),c=*pbuf++;
	while(c>=48&&c<=57);
	return x;
}
const int N=2000003,M=3000003;
typedef long long ll;
int n,q,m;
vector<int> vec[N],id[N];
int deg[N];
int a[M],rev[M];
int ver[M],pos[M],seq[M];
bool vis[N];
void dfs(int u,int las,int fa){
	for(int i=0;i<deg[u];++i){
		int v=vec[u][i],w=id[u][i];
		if(v==fa){rev[las]=w;rev[w]=las;}
		else dfs(v,w,u);
	}
	for(int i=0;i<deg[u];++i)
		a[rev[id[u][i]]]=id[u][(i+1)%deg[u]];
}
int f[M];
int rt(int x){
	if(f[x]==x) return x;
	return f[x]=rt(f[x]);
}
struct qry{
	ll val;int id;
	friend bool operator<(const qry x,const qry y){
		return x.val<y.val;
	}
}s[N];
int res[N];
int main(){
	freopen("dfs.in","r",stdin);
	freopen("dfs.out","w",stdout);
	fread(buf,1,1<<25,stdin);
	n=read<int>();q=read<int>();
	for(int i=1;i<=n;++i){
		int k=read<int>();
		deg[i]=k;
		vec[i].resize(k);
		id[i].resize(k);
		for(int j=0;j<k;++j)
			ver[id[i][j]=++m]=vec[i][j]=read<int>();
	}
	dfs(1,0,0);
	int p=1,num=0;
	do seq[pos[p]=num++]=p,p=a[p],f[p]=p;while(p!=1);
	for(int i=1;i<=q;++i){
		s[i].val=read<ll>();
		s[i].id=i;
	}
	sort(s+1,s+q+1);
	ll cur=0;
	int x=1,hd=1;
	for(int i=1;i<=n;++i){
		vis[x]=1;
		int L=id[x][1%deg[x]],R=L;
		while(vis[ver[R]]){
			R=rt(R);
			int _R=a[R];
			if(vis[ver[_R]]){
				if(rt(_R)==R){
					while(hd<=q){
						res[s[hd].id]=ver[seq[(pos[L]+s[hd].val-cur-1)%m]];
						++hd;
					}
					goto end;
				}
				else f[R]=_R;
			}
			else R=_R;
		}
		ll tmp=cur;
		tmp+=pos[R]-pos[L]+1;
		if(pos[R]<pos[L]) tmp+=m;
		while(hd<=q&&s[hd].val<=tmp){
			res[s[hd].id]=ver[seq[(pos[L]+s[hd].val-cur-1)%m]];
			++hd;
		}
		if(hd>q) break;
		x=ver[R];cur=tmp;
	}
end:
	for(int i=1;i<=q;++i) printf("%d\n",res[i]);
	return 0;
}
